﻿



var totalPriceAdults=0;
var totalPriceChild = 0;
var totalPriceBaby = 0;
var totalPriceVat = 0;
var totalPrice = 0;


TotalPriceAdults = function () {
    var priceAirAdults = parseInt($("#TotalTicketAirPricesAdults").html());
    var priceStationAdults = parseInt($("#TotalTicketStationPricesAdults").html());
    var priceCarAdults = parseInt($("#TotalTicketCarPricesAdults").html());
    var priceRestaurantAdults = parseInt($("#TotalMenuAdults").html());
    var priceHotelAdults = parseInt($("#TotalTicketHotelPricesAdults").html());
    var priceShipAdults = parseInt($("#TotalTicketShipPricesAdults").html());
    var priceServiceAdults = parseInt($("#TotalDvkAdults").html());
    var priceTravelGuideAdults = parseInt($("#TotalTravelGuidePricesAdults").html());
    var priceCommissionAdults = parseInt($("#TotalHHAdults").html());
    var priceInsuranceAdults = parseInt($("#TotalInsurancePricesAdults").html());
    var priceVisaAdults = parseInt($("#TotalVisaAdults").html());
    var priceGiftsAdults = parseInt($("#TotalGiftsAdults").html());
    

    totalPriceAdults = priceAirAdults + priceStationAdults + priceCarAdults + priceRestaurantAdults +
                    priceHotelAdults + priceServiceAdults + priceTravelGuideAdults + priceCommissionAdults +
                    priceInsuranceAdults + priceVisaAdults + priceShipAdults + priceGiftsAdults;
    $("#TotalPriceCaculatorAdults").html(totalPriceAdults);
};
TotalPriceChild = function () {
    var priceAirChild = parseInt($("#TotalTicketAirPricesChild").html());
    var priceStationChild = parseInt($("#TotalTicketStationPricesChild").html());
    var priceCarChild = parseInt($("#TotalTicketCarPricesChild").html());
    var priceRestaurantChild = parseInt($("#TotalMenuChild").html());
    var priceHotelChild = parseInt($("#TotalTicketHotelPricesChild").html());
    var priceServiceChild = parseInt($("#TotalDvkChild").html());
    var priceTravelGuideChild = parseInt($("#TotalTravelGuidePricesChild").html());
    var priceCommissionChild = parseInt($("#TotalHHChild").html());
    var priceInsuranceChild = parseInt($("#TotalInsurancePricesChild").html());
    var priceVisaChild = parseInt($("#TotalVisaChild").html());
    var priceShipChild = parseInt($("#TotalTicketShipPricesChild").html());
    var priceGiftsChild = parseInt($("#TotalGiftsChild ").html());
    
    totalPriceChild = priceAirChild + priceStationChild + priceCarChild + priceRestaurantChild +
        priceHotelChild + priceServiceChild + priceTravelGuideChild + priceCommissionChild +
        priceInsuranceChild + priceVisaChild + priceShipChild + priceGiftsChild;
    $("#TotalPriceCaculatorChild").html(totalPriceChild);
};
TotalPriceBaby = function () {
    var priceAirBaby = parseInt($("#TotalTicketAirPricesBaby").html());
    var priceStationBaby = parseInt($("#TotalTicketStationPricesBaby").html());
    var priceRestaurantBaby = parseInt($("#TotalMenuBaby").html());
    var priceHotelBaby = parseInt($("#TotalTicketHotelPricesBaby").html());
    var priceServiceBaby = parseInt($("#TotalDvkBaby").html());
    var priceCommissionBaby = parseInt($("#TotalHHBaby").html());
    var priceInsuranceBaby = parseInt($("#TotalInsurancePricesBaby").html());
    var priceVisaBaby = parseInt($("#TotalVisaBaby").html());
    var priceShipBaby = parseInt($("#TotalTicketShipPricesBaby").html());
    var priceGiftsBaby = parseInt($("#TotalGiftsBaby").html());

    
    totalPriceBaby = priceAirBaby + priceStationBaby + priceRestaurantBaby + priceHotelBaby +
        priceServiceBaby + priceCommissionBaby + priceInsuranceBaby + priceVisaBaby +
        priceShipBaby + priceGiftsBaby;
    $("#TotalPriceCaculatorBaby").html(totalPriceBaby);
    
};

TotalPriceVat = function () {
    var priceAirVat = parseInt($("#TotalVatAir").html());
    var priceStationVat = parseInt($("#TotalVatStation").html());
    var priceRestaurantVat = parseInt($("#TotalVatRestaurant").html());
    var priceHotelVat = parseInt($("#TotalVatHotel").html());
    var priceServiceVat = parseInt($("#TotalVatService").html());
    var priceCommissionVat = parseInt($("#TotalVatCommission").html());
    var priceInsuranceVat = parseInt($("#TotalVatInsurance").html());
    var priceVisaVat = parseInt($("#TotalVatVisa").html());
    var priceShipVat = parseInt($("#TotalVatShip").html());
    var priceGiftsVat = parseInt($("#TotalVatGifts").html());
    var priceTravelGuideVat = parseInt($("#TotalVatTravelGuide").html());
    var priceCarVat = parseInt($("#TotalVatCar").html());

    totalPriceVat = priceAirVat + priceStationVat + priceRestaurantVat + priceHotelVat +
        priceServiceVat + priceCommissionVat + priceInsuranceVat + priceVisaVat +
        priceShipVat + priceGiftsVat + priceTravelGuideVat + priceCarVat;
    $("#TotalVatCaculator").html(totalPriceVat);

};
//TotalPrice = function (quantityAdults, quantityChild, quantityBaby) {
TotalPrice = function () {
    TotalPriceAdults();
    TotalPriceChild();
    TotalPriceBaby();
    TotalPriceVat();
    //var totalPriceCaculator = totalPriceAdults * quantityAdults + totalPriceChild * quantityChild + totalPriceBaby * quantityBaby;
    //$("#TotalPriceCaculator").html(totalPriceCaculator);
    var priceAir = parseInt($("#TotalTicketAirPrices").html());
    var priceStation = parseInt($("#TotalTicketStationPrices").html());
    var priceCar = parseInt($("#TotalTicketCarPrices").html());
    var priceRestaurant = parseInt($("#TotalMenuPrices").html());
    var priceHotel = parseInt($("#TotalTicketHotelPrices").html());
    var priceService = parseInt($("#TotalDvkPrices").html());
    var priceTravelGuide = parseInt($("#TotalTravelGuidePrices").html());
    var priceCommission = parseInt($("#TotalHHPrices").html());
    var priceInsurance = parseInt($("#TotalInsurancePrices").html());
    var priceVisa = parseInt($("#TotalVisaPrices").html());
    var priceShip = parseInt($("#TotalTicketShipPrices").html());
    var priceGifts = parseInt($("#TotalGiftsPrices").html());
    
    totalPrice = priceAir + priceStation + priceCar + priceRestaurant +
        priceHotel + priceService + priceTravelGuide + priceCommission +
        priceInsurance + priceVisa + priceShip + priceGifts;
    $("#TotalPriceCaculator").html(totalPrice);
    
};
TotalSalePriceCalculator = function (salePriceAdultsElement, salePriceChildElement, salePariceBabyElement,
            totalSalePriceElement, priceOnCustomerElement, quantityAdults, quantityChild, quantityBaby) {
    //ham tinh tong gia ban doan
    
        var salePriceAdults = $(salePriceAdultsElement).val();
        var salePriceChild = $(salePriceChildElement).val();
        var salePriceBaby = $(salePariceBabyElement).val();
        var totalSalePrice = $(totalSalePriceElement).val();
        var priceOnCustomer = $(priceOnCustomerElement).val();

        var saleAdults = 0;
        var saleChild = 0;
        var saleBaby = 0;
        var totalSale = 0;
        var totalVat = 0;
        var chiPhiQuanLy = 0;
        var thueThuNhap = 0;
        var vatChenhLech = 0;
        var laiRongDoan = 0;

        var profitAdults = 0;
        var profitChild = 0;
        var profitBaby = 0;
        var profit = 0;

        if (priceOnCustomer > 0) {
            chiPhiQuanLy = priceOnCustomer * (parseInt(quantityAdults) + parseInt(quantityChild) + parseInt(quantityBaby));
        }
        if (salePriceAdults > 0 && salePriceAdults < 100) {
            saleAdults = totalPriceAdults + totalPriceAdults * (salePriceAdults / 100);
            profitAdults = totalPriceAdults * (salePriceAdults / 100);
        }
        if (salePriceChild > 0 && salePriceChild < 100) {
            saleChild = totalPriceChild + totalPriceChild * (salePriceChild / 100);
            profitChild = totalPriceChild * (salePriceChild / 100);
        }
        if (salePriceBaby > 0 && salePriceBaby < 100) {
            saleBaby = totalPriceBaby + totalPriceBaby * (salePriceBaby / 100);
            profitBaby = totalPriceBaby * (salePriceBaby / 100);
        }
        if (totalSalePrice > 0 && totalSalePrice < 100) {
            totalSale = totalPrice + totalPrice * (totalSalePrice / 100);
            profit = totalPrice * (totalSalePrice / 100);
            totalVat = totalSale * 0.1;
            vatChenhLech = totalVat - totalPriceVat;
        }
        if (profit > chiPhiQuanLy) {
            thueThuNhap = (profit - chiPhiQuanLy) * 0.23;
            laiRongDoan = profit - chiPhiQuanLy - thueThuNhap;
        }

        $('#TotalSaleCaculatorAdults').html(saleAdults);
        $('#TotalSaleCaculatorChild').html(saleChild);
        $('#TotalSaleCaculatorBaby').html(saleBaby);
        $('#TotalSaleCaculator').html(totalSale);
        $('#TotalSaleVatCaculator').html(totalVat);

        $('#ProfitCaculatorAdults').html(profitAdults);
        $('#ProfitCaculatorChild').html(profitChild);
        $('#ProfitCaculatorBaby').html(profitBaby);
        $('#ProfitCaculator').html(profit);

        $('#ChenhLechVat').html(vatChenhLech);
        $('#ChiPhiQuanLy').html(chiPhiQuanLy);
        $('#ThueThuNhap').html(thueThuNhap);
        $('#LaiRongDoan').html(laiRongDoan);

};

$('.service > table').hide();

$('#li-air').click(function() {
    $('#table-air').slideToggle('slow');
});
$('#li-station').click(function () {
    $('#table-station').slideToggle('slow');
});
$('#li-car').click(function () {
    $('#table-car').slideToggle('slow');
});
$('#li-insurance').click(function () {
    $('#table-insurance').slideToggle('slow');
});
$('#li-restaurant').click(function () {
    $('#table-restaurant').slideToggle('slow');
});
$('#li-commission').click(function () {
    $('#table-commission').slideToggle('slow');
});
$('#li-service').click(function () {
    $('#table-service').slideToggle('slow');
});
$('#li-visa').click(function () {
    $('#table-visa').slideToggle('slow');
});
$('#li-travel-guide').click(function () {
    $('#table-travel-guide').slideToggle('slow');
});
$('#li-hotel').click(function () {
    $('#table-hotel').slideToggle('slow');
});
$('#li-ship').click(function () {
    $('#table-ship').slideToggle('slow');
});
$('#li-gifts').click(function () {
    $('#table-gifts').slideToggle('slow');
    
   
});
$('#li-calculator').click(function () {
    $('.table-calculator').slideToggle('slow');
});
    
    
ProfitCalculator = function (percentAdultsElement, percentChildElement, percentBabyElement, percentTotalElement, priceOnCustomerElement, note1Element, note2Element, note3Element, note4Element, note5Element, note6Element, note7Element, note8Element, note9Element, note10Element, note11Element, note12Element, note13Element, note14Element, note15Element, note16Element,tourId,profitCalculatorId) {
    var fncInsertProfitCalculator = function() {
        var percentAdults = $(percentAdultsElement).val();
        if (percentAdults < 0 || percentAdults > 100 || percentAdults=="") { percentAdults = 0; }
        var percentChild = $(percentChildElement).val();
        if (percentChild < 0 || percentChild > 100 || percentChild == "") { percentChild = 0; }
        var percentBaby = $(percentBabyElement).val();
        if (percentBaby < 0 || percentBaby > 100 || percentBaby == "") { percentBaby = 0; }
        var percentTotal = $(percentTotalElement).val();
        if (percentTotal < 0 || percentTotal > 100 || percentTotal == "") { percentTotal = 0; }
        var priceOnCustomer = $(priceOnCustomerElement).val();
        if (priceOnCustomer < 0 || priceOnCustomer == "") { priceOnCustomer = 0; }
        var note1 = $(note1Element).val();
        var note2 = $(note2Element).val();
        var note3 = $(note3Element).val();
        var note4 = $(note4Element).val();
        var note5 = $(note5Element).val();
        var note6 = $(note6Element).val();
        var note7 = $(note7Element).val();
        var note8 = $(note8Element).val();
        var note9 = $(note9Element).val();
        var note10 = $(note10Element).val();
        var note11 = $(note11Element).val();
        var note12 = $(note12Element).val();
        var note13 = $(note13Element).val();
        var note14 = $(note14Element).val();
        var note15 = $(note15Element).val();
        var note16 = $(note16Element).val();

        $.ajax({
            type: "POST",
            url: "/ajax_vmh.html",
            data: {
                "function": "InsertProfitCalculator", 'profitCalculatorId': profitCalculatorId, "tourId": tourId, 'percentAdults': percentAdults, 'percentChild': percentChild,
                'percentBaby': percentBaby, 'percentTotal': percentTotal, 'priceOnCustomer': priceOnCustomer, 'note1': note1,
                'note2': note2, 'note3': note3, 'note4': note4, 'note5': note5, 'note6': note6, 'note7': note7, 'note8': note8,
                'note9': note9, 'note10': note10, 'note11': note11, 'note12': note12, 'note13': note13, 'note14': note14, 'note15': note15, 'note16': note16
            },
            dataType: "json",
            success: function (data) {


            }
            
        });
        hidePopup('profit-note1');
        hidePopup('profit-note2');
        hidePopup('profit-note3');
        hidePopup('profit-note4');
        hidePopup('profit-note5');
        hidePopup('profit-note6');
        hidePopup('profit-note7');
        hidePopup('profit-note8');
        hidePopup('profit-note9');
        hidePopup('profit-note10');
        hidePopup('profit-note11');
        hidePopup('profit-note12');
        hidePopup('profit-note13');
        hidePopup('profit-note14');
        hidePopup('profit-note15');
        hidePopup('profit-note16');
    };

    $('.btnInsertProfitNote').click(fncInsertProfitCalculator);
    $(percentAdultsElement).change(fncInsertProfitCalculator);
    $(percentChildElement).change(fncInsertProfitCalculator);
    $(percentBabyElement).change(fncInsertProfitCalculator);
    $(percentTotalElement).change(fncInsertProfitCalculator);
    $(priceOnCustomerElement).change(fncInsertProfitCalculator);
};
$('ul.classname >li#li-air').attr('image', 'up');
$('ul.classname >li#li-air').click(function () {
    if ($(this).attr('image') == 'up') {
        $('ul.classname >li#li-air').html('<a class="t_stt">1</a><span>CHIẾT TÍNH VÉ MÁY BAY</span><img src="../images/icon/up.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'down');
    } else {
        $('ul.classname >li#li-air').html('<a class="t_stt">1</a><span>CHIẾT TÍNH VÉ MÁY BAY</span><img src="../images/icon/down.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'up');
    }

});
$('ul.classname >li#li-car').attr('image', 'up');
$('ul.classname >li#li-car').click(function () {
    if ($(this).attr('image') == 'up') {
        $('ul.classname >li#li-car').html('<a class="t_stt">2</a><span>CHIẾT TÍNH XE HƠI</span><img src="../images/icon/up.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'down');
    } else {
        $('ul.classname >li#li-car').html('<a class="t_stt">2</a><span>CHIẾT TÍNH XE HƠI</span><img src="../images/icon/down.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'up');
    }

});
$('ul.classname >li#li-station').attr('image', 'up');
$('ul.classname >li#li-station').click(function () {
    if ($(this).attr('image') == 'up') {
        $('ul.classname >li#li-station').html('<a class="t_stt">3</a>CHIẾT TÍNH VÉ TÀU HỎA<img src="../images/icon/up.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'down');
    } else {
        $('ul.classname >li#li-station').html('<a class="t_stt">3</a>CHIẾT TÍNH VÉ TÀU HỎA<img src="../images/icon/down.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'up');
    }

});
$('ul.classname >li#li-hotel').attr('image', 'up');
$('ul.classname >li#li-hotel').click(function () {
    if ($(this).attr('image') == 'up') {
        $('ul.classname >li#li-hotel').html('<a class="t_stt">4</a>CHIẾT TÍNH LƯU TRÚ<img src="../images/icon/up.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'down');
    } else {
        $('ul.classname >li#li-hotel').html('<a class="t_stt">4</a>CHIẾT TÍNH LƯU TRÚ<img src="../images/icon/down.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'up');
    }

});
$('ul.classname >li#li-ship').attr('image', 'up');
$('ul.classname >li#li-ship').click(function () {
    if ($(this).attr('image') == 'up') {
        $('ul.classname >li#li-ship').html('<a class="t_stt">5</a>CHIẾT TÍNH TÀU THỦY<img src="../images/icon/up.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'down');
    } else {
        $('ul.classname >li#li-ship').html('<a class="t_stt">5</a>CHIẾT TÍNH TÀU THỦY<img src="../images/icon/down.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'up');
    }

});
$('ul.classname >li#li-restaurant').attr('image', 'up');
$('ul.classname >li#li-restaurant').click(function () {
    if ($(this).attr('image') == 'up') {
        $('ul.classname >li#li-restaurant').html('<a class="t_stt">6</a>CHIẾT TÍNH NHÀ HÀNG<img src="../images/icon/up.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'down');
    } else {
        $('ul.classname >li#li-restaurant').html('<a class="t_stt">6</a>CHIẾT TÍNH NHÀ HÀNG<img src="../images/icon/down.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'up');
    }

});
$('ul.classname >li#li-service').attr('image', 'up');
$('ul.classname >li#li-service').click(function () {
    if ($(this).attr('image') == 'up') {
        $('ul.classname >li#li-service').html('<a class="t_stt">7</a>CHIẾT TÍNH DỊCH VỤ<img src="../images/icon/up.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'down');
    } else {
        $('ul.classname >li#li-service').html('<a class="t_stt">7</a>CHIẾT TÍNH DỊCH VỤ<img src="../images/icon/down.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'up');
    }

});
$('ul.classname >li#li-travel-guide').attr('image', 'up');
$('ul.classname >li#li-travel-guide').click(function () {
    if ($(this).attr('image') == 'up') {
        $('ul.classname >li#li-travel-guide').html('<a class="t_stt">8</a>CHIẾT TÍNH HƯỚNG DẪN VIÊN<img src="../images/icon/up.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'down');
    } else {
        $('ul.classname >li#li-travel-guide').html('<a class="t_stt">8</a>CHIẾT TÍNH HƯỚNG DẪN VIÊN<img src="../images/icon/down.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'up');
    }

});
$('ul.classname >li#li-insurance').attr('image', 'up');
$('ul.classname >li#li-insurance').click(function () {
    if ($(this).attr('image') == 'up') {
        $('ul.classname >li#li-insurance').html('<a class="t_stt">9</a>CHIẾT TÍNH BẢO HIỂM<img src="../images/icon/up.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'down');
    } else {
        $('ul.classname >li#li-insurance').html('<a class="t_stt">9</a>CHIẾT TÍNH BẢO HIỂM<img src="../images/icon/down.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'up');
    }

});

$('ul.classname >li#li-visa').attr('image', 'up');
$('ul.classname >li#li-visa').click(function () {
    if ($(this).attr('image') == 'up') {
        $('ul.classname >li#li-visa').html('<a class="t_stt">10</a>CHIẾT TÍNH VISA<img src="../images/icon/up.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'down');
    } else {
        $('ul.classname >li#li-visa').html('<a class="t_stt">10</a>CHIẾT TÍNH VISA<img src="../images/icon/down.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'up');
    }

});

$('ul.classname >li#li-gifts').attr('image', 'up');
$('ul.classname >li#li-gifts').click(function () {
    if ($(this).attr('image') == 'up') {
        $('ul.classname >li#li-gifts').html('<a class="t_stt">11</a>CHIẾT TÍNH QUÀ TẶNG<img src="../images/icon/up.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'down');
    } else {
        $('ul.classname >li#li-gifts').html('<a class="t_stt">11</a>CHIẾT TÍNH QUÀ TẶNG<img src="../images/icon/down.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'up');
    }

});
$('ul.classname >li#li-commission').attr('image', 'up');
$('ul.classname >li#li-commission').click(function () {
    if ($(this).attr('image') == 'up') {
        $('ul.classname >li#li-commission').html('<a class="t_stt">12</a>CHIẾT TÍNH HOA HỒNG<img src="../images/icon/up.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'down');
    } else {
        $('ul.classname >li#li-commission').html('<a class="t_stt">12</a>CHIẾT TÍNH HOA HỒNG<img src="../images/icon/down.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'up');
    }

});
$('ul.classname >li#li-calculator').attr('image', 'up');
$('ul.classname >li#li-calculator').click(function () {
    if ($(this).attr('image') == 'up') {
        $('ul.classname >li#li-calculator').html('<a class="t_stt">13</a>CHIẾT TÍNH<img src="../images/icon/up.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'down');
    } else {
        $('ul.classname >li#li-calculator').html('<a class="t_stt">13</a>CHIẾT TÍNH<img src="../images/icon/down.png" style="float:right;margin-top: 5px; margin-right:20px;"/>');
        $(this).attr('image', 'up');
    }

});